package javaBean;

import java.lang.reflect.Constructor;

public class AccessPersonConstructors {
    public static void main(String[] args) {
        try {
            Class clz = Class.forName("javaBean.Person");
            Object obj = clz.newInstance();
            System.out.println(obj);

            //示例7
            Constructor c1 = clz.getDeclaredConstructor();
            obj = c1.newInstance();
            System.out.println(obj);

            Constructor c2 = clz.getDeclaredConstructor(String.class);
            c2.setAccessible(true);
            obj = c2.newInstance("New Person");
            System.out.println(obj);

            Constructor c3 = clz.getDeclaredConstructor(String.class,String.class,String.class);
            c3.setAccessible(true);
            obj = c3.newInstance("New Person","beijing","hello");
            System.out.println(obj);

        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
